import http from '@/utils/request'

export const apiGetPublicKey = (): Promise<string> => {
  return http({
    url: '/api/v1/auth/pubickey',
    method: 'get'
  })
}

export const apiGetCaptcha = (): Promise<string> => {
  return http({
    url: '/api/v1/auth/captcha',
    method: 'get'
  })
}

export const apiAccountLogin = (data): Promise<string> => {
  return http({
    url: '/api/v1/auth/login',
    method: 'post',
    data
  })
}

export const apiSendEmailGetCode = (email: string): Promise<void> => {
  return http({
    url: '/api/v1/email',
    method: 'post',
    data: { email }
  })
}

export const apiEmailCodeLogin = (data): Promise<string> => {
  return http({
    url: '/api/v1/auth/email',
    method: 'post',
    data
  })
}

export const apiRegisterUser = (data): Promise<string> => {
  return http({
    url: '/api/v1/user',
    method: 'post',
    data
  })
}

export const apiGetUserProfile = <T>(): Promise<T> => {
  return http({
    url: '/api/v1/auth/profile',
    method: 'get'
  })
}

export const apiOauthGiteeSignin = <T>(params): Promise<T> => {
  return http({
    url: '/api/v1/auth/oauth-gitee',
    method: 'post',
    params
  })
}

export const apiOauthGithubSignin = <T>(params): Promise<T> => {
  return http({
    url: '/api/v1/auth/oauth-github',
    method: 'post',
    params
  })
}

export const apiUpdateUserProfile = <T>(data): Promise<T> => {
  return http({
    url: '/api/v1/user/profile',
    method: 'put',
    data
  })
}

export const apiUpdateUserAvatar = <T>(avatar: string): Promise<T> => {
  return http({
    url: '/api/v1/user/avatar',
    method: 'put',
    data: { avatar }
  })
}
